<?php
if (session_id() == "") session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include_once "ewcfg8.php" ?>
<?php include_once "ewmysql8.php" ?>
<?php include_once "phpfn8.php" ?>
<?php include_once "iteminfo.php" ?>
<?php include_once "categoryinfo.php" ?>
<?php include_once "userfn8.php" ?>
<?php ew_Header(TRUE) ?>
<?php

// Create page object
$item_edit = new citem_edit();
$Page =& $item_edit;

// Page init
$item_edit->Page_Init();

// Page main
$item_edit->Page_Main();
?>
<?php include_once "header.php" ?>
<script type="text/javascript">
<!--

// Create page object
var item_edit = new ew_Page("item_edit");

// page properties
item_edit.PageID = "edit"; // page ID
item_edit.FormID = "fitemedit"; // form ID
var EW_PAGE_ID = item_edit.PageID; // for backward compatibility

// extend page with ValidateForm function
item_edit.ValidateForm = function(fobj) {
	ew_PostAutoSuggest(fobj);
	if (!this.ValidateRequired)
		return true; // ignore validation
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = 1;
	for (i=0; i<rowcnt; i++) {
		infix = "";
		elm = fobj.elements["x" + infix + "_category_id"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($item->category_id->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_name"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($item->name->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_content"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($item->content->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_price_wm"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($item->price_wm->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_price_wm"];
		if (elm && !ew_CheckNumber(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($item->price_wm->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_price_em"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($item->price_em->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_price_em"];
		if (elm && !ew_CheckNumber(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($item->price_em->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_price_wm_ahli"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($item->price_wm_ahli->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_price_wm_ahli"];
		if (elm && !ew_CheckNumber(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($item->price_wm_ahli->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_price_em_ahli"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($item->price_em_ahli->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_price_em_ahli"];
		if (elm && !ew_CheckNumber(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($item->price_em_ahli->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_weight"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($item->weight->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_weight"];
		if (elm && !ew_CheckNumber(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($item->weight->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_kod"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($item->kod->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_rate"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($item->rate->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_image"];
		aelm = fobj.elements["a" + infix + "_image"];
		var chk_image = (aelm && aelm[0])?(aelm[2].checked):true;
		if (elm && chk_image && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($item->image->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_image"];
		if (elm && !ew_CheckFileType(elm.value))
			return ew_OnError(this, elm, ewLanguage.Phrase("WrongFileType"));
		elm = fobj.elements["x" + infix + "_bigimage"];
		if (elm && !ew_CheckFileType(elm.value))
			return ew_OnError(this, elm, ewLanguage.Phrase("WrongFileType"));

		// Set up row object
		var row = {};
		row["index"] = infix;
		for (var j = 0; j < fobj.elements.length; j++) {
			var el = fobj.elements[j];
			var len = infix.length + 2;
			if (el.name.substr(0, len) == "x" + infix + "_") {
				var elname = "x_" + el.name.substr(len);
				if (ewLang.isObject(row[elname])) { // already exists
					if (ewLang.isArray(row[elname])) {
						row[elname][row[elname].length] = el; // add to array
					} else {
						row[elname] = [row[elname], el]; // convert to array
					}
				} else {
					row[elname] = el;
				}
			}
		}
		fobj.row = row;

		// Call Form Custom Validate event
		if (!this.Form_CustomValidate(fobj)) return false;
	}

	// Process detail page
	var detailpage = (fobj.detailpage) ? fobj.detailpage.value : "";
	if (detailpage != "") {
		return eval(detailpage+".ValidateForm(fobj)");
	}
	return true;
}

// extend page with Form_CustomValidate function
item_edit.Form_CustomValidate =  
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
<?php if (EW_CLIENT_VALIDATE) { ?>
item_edit.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
item_edit.ValidateRequired = false; // no JavaScript validation
<?php } ?>

//-->
</script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
<!--
_width_multiplier = 20;
_height_multiplier = 60;
var ew_DHTMLEditors = [];

// update value from editor to textarea
function ew_UpdateTextArea() {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {			
		var inst;			
		for (inst in CKEDITOR.instances)
			CKEDITOR.instances[inst].updateElement();
	}
}

// update value from textarea to editor
function ew_UpdateDHTMLEditor(name) {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {
		var inst = CKEDITOR.instances[name];		
		if (inst)
			inst.setData(inst.element.value);
	}
}

// focus editor
function ew_FocusDHTMLEditor(name) {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {
		var inst = CKEDITOR.instances[name];	
		if (inst)
			inst.focus();
	}
}

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
//-->

</script>
<p class="phpmaker ewTitle"><?php echo $Language->Phrase("Edit") ?>&nbsp;<?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $item->TableCaption() ?></p>
<p class="phpmaker"><a href="<?php echo $item->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></p>
<?php $item_edit->ShowPageHeader(); ?>
<?php
$item_edit->ShowMessage();
?>
<form name="fitemedit" id="fitemedit" action="<?php echo ew_CurrentPage() ?>" method="post" enctype="multipart/form-data" onsubmit="return item_edit.ValidateForm(this);">
<p>
<input type="hidden" name="a_table" id="a_table" value="item">
<input type="hidden" name="a_edit" id="a_edit" value="U">
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($item->id->Visible) { // id ?>
	<tr id="r_id"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->id->FldCaption() ?></td>
		<td<?php echo $item->id->CellAttributes() ?>><span id="el_id">
<div<?php echo $item->id->ViewAttributes() ?>><?php echo $item->id->EditValue ?></div>
<input type="hidden" name="x_id" id="x_id" value="<?php echo ew_HtmlEncode($item->id->CurrentValue) ?>">
</span><?php echo $item->id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($item->category_id->Visible) { // category_id ?>
	<tr id="r_category_id"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->category_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $item->category_id->CellAttributes() ?>><span id="el_category_id">
<?php if ($item->category_id->getSessionValue() <> "") { ?>
<div<?php echo $item->category_id->ViewAttributes() ?>><?php echo $item->category_id->ViewValue ?></div>
<input type="hidden" id="x_category_id" name="x_category_id" value="<?php echo ew_HtmlEncode($item->category_id->CurrentValue) ?>">
<?php } else { ?>
<select id="x_category_id" name="x_category_id"<?php echo $item->category_id->EditAttributes() ?>>
<?php
if (is_array($item->category_id->EditValue)) {
	$arwrk = $item->category_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($item->category_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
&nbsp;<a name="aol_x_category_id" id="aol_x_category_id" href="javascript:void(0);" onclick="ew_AddOptDialogShow({pg:item_edit,lnk:'aol_x_category_id',el:'x_category_id',hdr:this.innerHTML, url:'categoryaddopt.php',lf:'x_id',df:'x_name',df2:'',df3:'',df4:'',pf:'',ff:''});"><?php echo $Language->Phrase("AddLink") ?>&nbsp;<?php echo $item->category_id->FldCaption() ?></a>
<?php } ?>
</span><?php echo $item->category_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($item->name->Visible) { // name ?>
	<tr id="r_name"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->name->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $item->name->CellAttributes() ?>><span id="el_name">
<input type="text" name="x_name" id="x_name" size="70" maxlength="255" value="<?php echo $item->name->EditValue ?>"<?php echo $item->name->EditAttributes() ?>>
</span><?php echo $item->name->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($item->description->Visible) { // description ?>
	<tr id="r_description"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->description->FldCaption() ?></td>
		<td<?php echo $item->description->CellAttributes() ?>><span id="el_description">
<textarea name="x_description" id="x_description" cols="70" rows="3"<?php echo $item->description->EditAttributes() ?>><?php echo $item->description->EditValue ?></textarea>
</span><?php echo $item->description->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($item->content->Visible) { // content ?>
	<tr id="r_content"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->content->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $item->content->CellAttributes() ?>><span id="el_content">
<textarea name="x_content" id="x_content" cols="40" rows="6"<?php echo $item->content->EditAttributes() ?>><?php echo $item->content->EditValue ?></textarea>
<script type="text/javascript">
<!--
<?php if ($item->content->ReadOnly) { ?>
new ew_ReadOnlyTextArea('x_content', 40*_width_multiplier, 6*_height_multiplier);
<?php } else { ?>ew_DHTMLEditors.push(new ew_DHTMLEditor("x_content", function() {
	var oCKeditor = CKEDITOR.replace('x_content', { width: 40*_width_multiplier, height: 6*_height_multiplier, autoUpdateElement: false, baseHref: 'ckeditor/'});
	this.active = true;
}));
<?php } ?>
-->
</script>
</span><?php echo $item->content->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($item->price_wm->Visible) { // price_wm ?>
	<tr id="r_price_wm"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->price_wm->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $item->price_wm->CellAttributes() ?>><span id="el_price_wm">
<input type="text" name="x_price_wm" id="x_price_wm" size="70" maxlength="10" value="<?php echo $item->price_wm->EditValue ?>"<?php echo $item->price_wm->EditAttributes() ?>>
</span><?php echo $item->price_wm->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($item->price_em->Visible) { // price_em ?>
	<tr id="r_price_em"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->price_em->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $item->price_em->CellAttributes() ?>><span id="el_price_em">
<input type="text" name="x_price_em" id="x_price_em" size="70" maxlength="10" value="<?php echo $item->price_em->EditValue ?>"<?php echo $item->price_em->EditAttributes() ?>>
</span><?php echo $item->price_em->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($item->price_wm_ahli->Visible) { // price_wm_ahli ?>
	<tr id="r_price_wm_ahli"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->price_wm_ahli->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $item->price_wm_ahli->CellAttributes() ?>><span id="el_price_wm_ahli">
<input type="text" name="x_price_wm_ahli" id="x_price_wm_ahli" size="70" value="<?php echo $item->price_wm_ahli->EditValue ?>"<?php echo $item->price_wm_ahli->EditAttributes() ?>>
</span><?php echo $item->price_wm_ahli->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($item->price_em_ahli->Visible) { // price_em_ahli ?>
	<tr id="r_price_em_ahli"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->price_em_ahli->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $item->price_em_ahli->CellAttributes() ?>><span id="el_price_em_ahli">
<input type="text" name="x_price_em_ahli" id="x_price_em_ahli" size="70" value="<?php echo $item->price_em_ahli->EditValue ?>"<?php echo $item->price_em_ahli->EditAttributes() ?>>
</span><?php echo $item->price_em_ahli->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($item->weight->Visible) { // weight ?>
	<tr id="r_weight"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->weight->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $item->weight->CellAttributes() ?>><span id="el_weight">
<input type="text" name="x_weight" id="x_weight" size="70" value="<?php echo $item->weight->EditValue ?>"<?php echo $item->weight->EditAttributes() ?>>
</span><?php echo $item->weight->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($item->kod->Visible) { // kod ?>
	<tr id="r_kod"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->kod->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $item->kod->CellAttributes() ?>><span id="el_kod">
<input type="text" name="x_kod" id="x_kod" size="70" maxlength="255" value="<?php echo $item->kod->EditValue ?>"<?php echo $item->kod->EditAttributes() ?>>
</span><?php echo $item->kod->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($item->rate->Visible) { // rate ?>
	<tr id="r_rate"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->rate->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $item->rate->CellAttributes() ?>><span id="el_rate">
<div id="tp_x_rate" class="<?php echo EW_ITEM_TEMPLATE_CLASSNAME ?>"><label><input type="radio" name="x_rate" id="x_rate" value="{value}"<?php echo $item->rate->EditAttributes() ?>></label></div>
<div id="dsl_x_rate" data-repeatcolumn="5" class="ewItemList">
<?php
$arwrk = $item->rate->EditValue;
if (is_array($arwrk)) {
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($item->rate->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " checked=\"checked\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;

		// Note: No spacing within the LABEL tag
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<label><input type="radio" name="x_rate" id="x_rate" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $item->rate->EditAttributes() ?>><?php echo $arwrk[$rowcntwrk][1] ?></label>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
	}
}
?>
</div>
</span><?php echo $item->rate->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($item->image->Visible) { // image ?>
	<tr id="r_image"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->image->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $item->image->CellAttributes() ?>><span id="el_image">
<div id="old_x_image">
<?php if ($item->image->LinkAttributes() <> "") { ?>
<?php if (!empty($item->image->Upload->DbValue)) { ?>
<img src="<?php echo ew_UploadPathEx(FALSE, $item->image->UploadPath) . $item->image->Upload->DbValue ?>" border=0<?php echo $item->image->ViewAttributes() ?>>
<?php } elseif (!in_array($item->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } else { ?>
<?php if (!empty($item->image->Upload->DbValue)) { ?>
<img src="<?php echo ew_UploadPathEx(FALSE, $item->image->UploadPath) . $item->image->Upload->DbValue ?>" border=0<?php echo $item->image->ViewAttributes() ?>>
<?php } elseif (!in_array($item->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } ?>
</div>
<div id="new_x_image">
<?php if (!empty($item->image->Upload->DbValue)) { ?>
<label><input type="radio" name="a_image" id="a_image" value="1" checked="checked"><?php echo $Language->Phrase("Keep") ?></label>&nbsp;
<label><input type="radio" name="a_image" id="a_image" value="2" disabled="disabled"><?php echo $Language->Phrase("Remove") ?></label>&nbsp;
<label><input type="radio" name="a_image" id="a_image" value="3"><?php echo $Language->Phrase("Replace") ?><br></label>
<?php $item->image->EditAttrs["onchange"] = "this.form.a_image[2].checked=true;" . @$item->image->EditAttrs["onchange"]; ?>
<?php } else { ?>
<input type="hidden" name="a_image" id="a_image" value="3">
<?php } ?>
<input type="file" name="x_image" id="x_image" size="70"<?php echo $item->image->EditAttributes() ?>>
</div>
</span><?php echo $item->image->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($item->bigimage->Visible) { // bigimage ?>
	<tr id="r_bigimage"<?php echo $item->RowAttributes() ?>>
		<td class="ewTableHeader"><?php echo $item->bigimage->FldCaption() ?></td>
		<td<?php echo $item->bigimage->CellAttributes() ?>><span id="el_bigimage">
<div id="old_x_bigimage">
<?php if ($item->bigimage->LinkAttributes() <> "") { ?>
<?php if (!empty($item->bigimage->Upload->DbValue)) { ?>
<img src="<?php echo ew_UploadPathEx(FALSE, $item->bigimage->UploadPath) . $item->bigimage->Upload->DbValue ?>" border=0<?php echo $item->bigimage->ViewAttributes() ?>>
<?php } elseif (!in_array($item->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } else { ?>
<?php if (!empty($item->bigimage->Upload->DbValue)) { ?>
<img src="<?php echo ew_UploadPathEx(FALSE, $item->bigimage->UploadPath) . $item->bigimage->Upload->DbValue ?>" border=0<?php echo $item->bigimage->ViewAttributes() ?>>
<?php } elseif (!in_array($item->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } ?>
</div>
<div id="new_x_bigimage">
<?php if (!empty($item->bigimage->Upload->DbValue)) { ?>
<label><input type="radio" name="a_bigimage" id="a_bigimage" value="1" checked="checked"><?php echo $Language->Phrase("Keep") ?></label>&nbsp;
<label><input type="radio" name="a_bigimage" id="a_bigimage" value="2"><?php echo $Language->Phrase("Remove") ?></label>&nbsp;
<label><input type="radio" name="a_bigimage" id="a_bigimage" value="3"><?php echo $Language->Phrase("Replace") ?><br></label>
<?php $item->bigimage->EditAttrs["onchange"] = "this.form.a_bigimage[2].checked=true;" . @$item->bigimage->EditAttrs["onchange"]; ?>
<?php } else { ?>
<input type="hidden" name="a_bigimage" id="a_bigimage" value="3">
<?php } ?>
<input type="file" name="x_bigimage" id="x_bigimage" size="70"<?php echo $item->bigimage->EditAttributes() ?>>
</div>
</span><?php echo $item->bigimage->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("EditBtn")) ?>">
</form>
<?php
$item_edit->ShowPageFooter();
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
?>
<script type="text/javascript">
<!--
ew_CreateEditor();  // Create DHTML editor(s)

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php include_once "footer.php" ?>
<?php
$item_edit->Page_Terminate();
?>
<?php

//
// Page class
//
class citem_edit {

	// Page ID
	var $PageID = 'edit';

	// Table name
	var $TableName = 'item';

	// Page object name
	var $PageObjName = 'item_edit';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		global $item;
		if ($item->UseTokenInUrl) $PageUrl .= "t=" . $item->TableVar . "&"; // Add page token
		return $PageUrl;
	}

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_MESSAGE], $v);
	}

	function getFailureMessage() {
		return @$_SESSION[EW_SESSION_FAILURE_MESSAGE];
	}

	function setFailureMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_FAILURE_MESSAGE], $v);
	}

	function getSuccessMessage() {
		return @$_SESSION[EW_SESSION_SUCCESS_MESSAGE];
	}

	function setSuccessMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_SUCCESS_MESSAGE], $v);
	}

	// Show message
	function ShowMessage() {
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage, "");
		if ($sMessage <> "") { // Message in Session, display
			echo "<p class=\"ewMessage\">" . $sMessage . "</p>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}

		// Success message
		$sSuccessMessage = $this->getSuccessMessage();
		$this->Message_Showing($sSuccessMessage, "success");
		if ($sSuccessMessage <> "") { // Message in Session, display
			echo "<p class=\"ewSuccessMessage\">" . $sSuccessMessage . "</p>";
			$_SESSION[EW_SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
		}

		// Failure message
		$sErrorMessage = $this->getFailureMessage();
		$this->Message_Showing($sErrorMessage, "failure");
		if ($sErrorMessage <> "") { // Message in Session, display
			echo "<p class=\"ewErrorMessage\">" . $sErrorMessage . "</p>";
			$_SESSION[EW_SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
		}
	}
	var $PageHeader;
	var $PageFooter;

	// Show Page Header
	function ShowPageHeader() {
		$sHeader = $this->PageHeader;
		$this->Page_DataRendering($sHeader);
		if ($sHeader <> "") { // Header exists, display
			echo "<p class=\"phpmaker\">" . $sHeader . "</p>";
		}
	}

	// Show Page Footer
	function ShowPageFooter() {
		$sFooter = $this->PageFooter;
		$this->Page_DataRendered($sFooter);
		if ($sFooter <> "") { // Fotoer exists, display
			echo "<p class=\"phpmaker\">" . $sFooter . "</p>";
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm, $item;
		if ($item->UseTokenInUrl) {
			if ($objForm)
				return ($item->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($item->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function citem_edit() {
		global $conn, $Language;

		// Language object
		if (!isset($Language)) $Language = new cLanguage();

		// Table object (item)
		if (!isset($GLOBALS["item"])) {
			$GLOBALS["item"] = new citem();
			$GLOBALS["Table"] =& $GLOBALS["item"];
		}

		// Table object (category)
		if (!isset($GLOBALS['category'])) $GLOBALS['category'] = new ccategory();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'edit', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'item', TRUE);

		// Start timer
		if (!isset($GLOBALS["gTimer"])) $GLOBALS["gTimer"] = new cTimer();

		// Open connection
		if (!isset($conn)) $conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
		global $item;

		// Security
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}

		// Create form object
		$objForm = new cFormObj();

		// Global Page Loading event (in userfn*.php)
		Page_Loading();

		// Page Load event
		$this->Page_Load();
	}

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();
		$this->Page_Redirecting($url);

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}
	var $DbMasterFilter;
	var $DbDetailFilter;

	// 
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsFormError, $item;

		// Load key from QueryString
		if (@$_GET["id"] <> "")
			$item->id->setQueryStringValue($_GET["id"]);

		// Set up master detail parameters
		$this->SetUpMasterParms();
		if (@$_POST["a_edit"] <> "") {
			$item->CurrentAction = $_POST["a_edit"]; // Get action code
			$this->LoadFormValues(); // Get form values

			// Validate form
			if (!$this->ValidateForm()) {
				$item->CurrentAction = ""; // Form error, reset action
				$this->setFailureMessage($gsFormError);
				$item->EventCancelled = TRUE; // Event cancelled
				$this->RestoreFormValues();
			}
		} else {
			$item->CurrentAction = "I"; // Default action is display
		}

		// Check if valid key
		if ($item->id->CurrentValue == "")
			$this->Page_Terminate("itemlist.php"); // Invalid key, return to list
		switch ($item->CurrentAction) {
			case "I": // Get a record to display
				if (!$this->LoadRow()) { // Load record based on key
					$this->setFailureMessage($Language->Phrase("NoRecord")); // No record found
					$this->Page_Terminate("itemlist.php"); // No matching record, return to list
				}
				break;
			Case "U": // Update
				$item->SendEmail = TRUE; // Send email on update success
				if ($this->EditRow()) { // Update record based on key
					$this->setSuccessMessage($Language->Phrase("UpdateSuccess")); // Update success
					$sReturnUrl = $item->getReturnUrl();
					$this->Page_Terminate($sReturnUrl); // Return to caller
				} else {
					$item->EventCancelled = TRUE; // Event cancelled
					$this->RestoreFormValues(); // Restore form values if update failed
				}
		}

		// Render the record
		$item->RowType = EW_ROWTYPE_EDIT; // Render as Edit
		$item->ResetAttrs();
		$this->RenderRow();
	}

	// Get upload files
	function GetUploadFiles() {
		global $objForm, $item;

		// Get upload data
		$index = $objForm->Index; // Save form index
		$objForm->Index = 0;
		$confirmPage = (strval($objForm->GetValue("a_confirm")) <> "");
		$objForm->Index = $index; // Restore form index
		$item->image->Upload->Index = $objForm->Index;
		$item->image->Upload->RestoreDbFromSession();
		if ($confirmPage) { // Post from confirm page
			$item->image->Upload->RestoreFromSession();
		} else {
			if ($item->image->Upload->UploadFile()) {

				// No action required
			} else {
				echo $item->image->Upload->Message;
				$this->Page_Terminate();
				exit();
			}
			$item->image->Upload->SaveToSession();
		}
		$item->bigimage->Upload->Index = $objForm->Index;
		$item->bigimage->Upload->RestoreDbFromSession();
		if ($confirmPage) { // Post from confirm page
			$item->bigimage->Upload->RestoreFromSession();
		} else {
			if ($item->bigimage->Upload->UploadFile()) {

				// No action required
			} else {
				echo $item->bigimage->Upload->Message;
				$this->Page_Terminate();
				exit();
			}
			$item->bigimage->Upload->SaveToSession();
		}
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm, $item;
		$this->GetUploadFiles(); // Get upload files
		if (!$item->id->FldIsDetailKey)
			$item->id->setFormValue($objForm->GetValue("x_id"));
		if (!$item->category_id->FldIsDetailKey) {
			$item->category_id->setFormValue($objForm->GetValue("x_category_id"));
		}
		if (!$item->name->FldIsDetailKey) {
			$item->name->setFormValue($objForm->GetValue("x_name"));
		}
		if (!$item->description->FldIsDetailKey) {
			$item->description->setFormValue($objForm->GetValue("x_description"));
		}
		if (!$item->content->FldIsDetailKey) {
			$item->content->setFormValue($objForm->GetValue("x_content"));
		}
		if (!$item->price_wm->FldIsDetailKey) {
			$item->price_wm->setFormValue($objForm->GetValue("x_price_wm"));
		}
		if (!$item->price_em->FldIsDetailKey) {
			$item->price_em->setFormValue($objForm->GetValue("x_price_em"));
		}
		if (!$item->price_wm_ahli->FldIsDetailKey) {
			$item->price_wm_ahli->setFormValue($objForm->GetValue("x_price_wm_ahli"));
		}
		if (!$item->price_em_ahli->FldIsDetailKey) {
			$item->price_em_ahli->setFormValue($objForm->GetValue("x_price_em_ahli"));
		}
		if (!$item->weight->FldIsDetailKey) {
			$item->weight->setFormValue($objForm->GetValue("x_weight"));
		}
		if (!$item->kod->FldIsDetailKey) {
			$item->kod->setFormValue($objForm->GetValue("x_kod"));
		}
		if (!$item->rate->FldIsDetailKey) {
			$item->rate->setFormValue($objForm->GetValue("x_rate"));
		}
		if (!$item->modified_date->FldIsDetailKey) {
			$item->modified_date->setFormValue($objForm->GetValue("x_modified_date"));
			$item->modified_date->CurrentValue = ew_UnFormatDateTime($item->modified_date->CurrentValue, 11);
		}
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm, $item;
		$this->LoadRow();
		$item->id->CurrentValue = $item->id->FormValue;
		$item->category_id->CurrentValue = $item->category_id->FormValue;
		$item->name->CurrentValue = $item->name->FormValue;
		$item->description->CurrentValue = $item->description->FormValue;
		$item->content->CurrentValue = $item->content->FormValue;
		$item->price_wm->CurrentValue = $item->price_wm->FormValue;
		$item->price_em->CurrentValue = $item->price_em->FormValue;
		$item->price_wm_ahli->CurrentValue = $item->price_wm_ahli->FormValue;
		$item->price_em_ahli->CurrentValue = $item->price_em_ahli->FormValue;
		$item->weight->CurrentValue = $item->weight->FormValue;
		$item->kod->CurrentValue = $item->kod->FormValue;
		$item->rate->CurrentValue = $item->rate->FormValue;
		$item->modified_date->CurrentValue = $item->modified_date->FormValue;
		$item->modified_date->CurrentValue = ew_UnFormatDateTime($item->modified_date->CurrentValue, 11);
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $item;
		$sFilter = $item->KeyFilter();

		// Call Row Selecting event
		$item->Row_Selecting($sFilter);

		// Load SQL based on filter
		$item->CurrentFilter = $sFilter;
		$sSql = $item->SQL();
		$res = FALSE;
		$rs = ew_LoadRecordset($sSql);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->LoadRowValues($rs); // Load row values
			$rs->Close();
		}
		return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn, $item;
		if (!$rs || $rs->EOF) return;

		// Call Row Selected event
		$row =& $rs->fields;
		$item->Row_Selected($row);
		$item->id->setDbValue($rs->fields('id'));
		$item->category_id->setDbValue($rs->fields('category_id'));
		if (array_key_exists('EV__category_id', $rs->fields)) {
			$item->category_id->VirtualValue = $rs->fields('EV__category_id'); // Set up virtual field value
		} else {
			$item->category_id->VirtualValue = ""; // Clear value
		}
		$item->name->setDbValue($rs->fields('name'));
		$item->description->setDbValue($rs->fields('description'));
		$item->content->setDbValue($rs->fields('content'));
		$item->price_wm->setDbValue($rs->fields('price_wm'));
		$item->price_em->setDbValue($rs->fields('price_em'));
		$item->price_wm_ahli->setDbValue($rs->fields('price_wm_ahli'));
		$item->price_em_ahli->setDbValue($rs->fields('price_em_ahli'));
		$item->weight->setDbValue($rs->fields('weight'));
		$item->kod->setDbValue($rs->fields('kod'));
		$item->rate->setDbValue($rs->fields('rate'));
		$item->image->Upload->DbValue = $rs->fields('image');
		$item->image->Upload->SaveDbToSession();
		$item->bigimage->Upload->DbValue = $rs->fields('bigimage');
		$item->bigimage->Upload->SaveDbToSession();
		$item->diskaun->setDbValue($rs->fields('diskaun'));
		$item->created_date->setDbValue($rs->fields('created_date'));
		$item->modified_date->setDbValue($rs->fields('modified_date'));
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $Language, $item;

		// Initialize URLs
		// Call Row_Rendering event

		$item->Row_Rendering();

		// Common render codes for all row types
		// id
		// category_id
		// name
		// description
		// content
		// price_wm
		// price_em
		// price_wm_ahli
		// price_em_ahli
		// weight
		// kod
		// rate
		// image
		// bigimage
		// diskaun
		// created_date
		// modified_date

		if ($item->RowType == EW_ROWTYPE_VIEW) { // View row

			// id
			$item->id->ViewValue = $item->id->CurrentValue;
			$item->id->ViewCustomAttributes = "";

			// category_id
			if ($item->category_id->VirtualValue <> "") {
				$item->category_id->ViewValue = $item->category_id->VirtualValue;
			} else {
			if (strval($item->category_id->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($item->category_id->CurrentValue) . "";
			$sSqlWrk = "SELECT `name` FROM `category`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$item->category_id->ViewValue = $rswrk->fields('name');
					$rswrk->Close();
				} else {
					$item->category_id->ViewValue = $item->category_id->CurrentValue;
				}
			} else {
				$item->category_id->ViewValue = NULL;
			}
			}
			$item->category_id->ViewCustomAttributes = "";

			// name
			$item->name->ViewValue = $item->name->CurrentValue;
			$item->name->ViewCustomAttributes = "";

			// description
			$item->description->ViewValue = $item->description->CurrentValue;
			$item->description->ViewCustomAttributes = "";

			// content
			$item->content->ViewValue = $item->content->CurrentValue;
			$item->content->ViewCustomAttributes = "";

			// price_wm
			$item->price_wm->ViewValue = $item->price_wm->CurrentValue;
			$item->price_wm->ViewCustomAttributes = "";

			// price_em
			$item->price_em->ViewValue = $item->price_em->CurrentValue;
			$item->price_em->ViewCustomAttributes = "";

			// price_wm_ahli
			$item->price_wm_ahli->ViewValue = $item->price_wm_ahli->CurrentValue;
			$item->price_wm_ahli->ViewCustomAttributes = "";

			// price_em_ahli
			$item->price_em_ahli->ViewValue = $item->price_em_ahli->CurrentValue;
			$item->price_em_ahli->ViewCustomAttributes = "";

			// weight
			$item->weight->ViewValue = $item->weight->CurrentValue;
			$item->weight->ViewCustomAttributes = "";

			// kod
			$item->kod->ViewValue = $item->kod->CurrentValue;
			$item->kod->ViewCustomAttributes = "";

			// rate
			if (strval($item->rate->CurrentValue) <> "") {
				switch ($item->rate->CurrentValue) {
					case "5":
						$item->rate->ViewValue = $item->rate->FldTagCaption(1) <> "" ? $item->rate->FldTagCaption(1) : $item->rate->CurrentValue;
						break;
					case "4":
						$item->rate->ViewValue = $item->rate->FldTagCaption(2) <> "" ? $item->rate->FldTagCaption(2) : $item->rate->CurrentValue;
						break;
					case "3":
						$item->rate->ViewValue = $item->rate->FldTagCaption(3) <> "" ? $item->rate->FldTagCaption(3) : $item->rate->CurrentValue;
						break;
					case "2":
						$item->rate->ViewValue = $item->rate->FldTagCaption(4) <> "" ? $item->rate->FldTagCaption(4) : $item->rate->CurrentValue;
						break;
					case "1":
						$item->rate->ViewValue = $item->rate->FldTagCaption(5) <> "" ? $item->rate->FldTagCaption(5) : $item->rate->CurrentValue;
						break;
					default:
						$item->rate->ViewValue = $item->rate->CurrentValue;
				}
			} else {
				$item->rate->ViewValue = NULL;
			}
			$item->rate->ViewCustomAttributes = "";

			// image
			if (!ew_Empty($item->image->Upload->DbValue)) {
				$item->image->ViewValue = $item->image->Upload->DbValue;
				$item->image->ImageAlt = $item->image->FldAlt();
			} else {
				$item->image->ViewValue = "";
			}
			$item->image->ViewCustomAttributes = "";

			// bigimage
			if (!ew_Empty($item->bigimage->Upload->DbValue)) {
				$item->bigimage->ViewValue = $item->bigimage->Upload->DbValue;
				$item->bigimage->ImageAlt = $item->bigimage->FldAlt();
			} else {
				$item->bigimage->ViewValue = "";
			}
			$item->bigimage->ViewCustomAttributes = "";

			// modified_date
			$item->modified_date->ViewValue = $item->modified_date->CurrentValue;
			$item->modified_date->ViewValue = ew_FormatDateTime($item->modified_date->ViewValue, 11);
			$item->modified_date->ViewCustomAttributes = "";

			// id
			$item->id->LinkCustomAttributes = "";
			$item->id->HrefValue = "";
			$item->id->TooltipValue = "";

			// category_id
			$item->category_id->LinkCustomAttributes = "";
			$item->category_id->HrefValue = "";
			$item->category_id->TooltipValue = "";

			// name
			$item->name->LinkCustomAttributes = "";
			$item->name->HrefValue = "";
			$item->name->TooltipValue = "";

			// description
			$item->description->LinkCustomAttributes = "";
			$item->description->HrefValue = "";
			$item->description->TooltipValue = "";

			// content
			$item->content->LinkCustomAttributes = "";
			$item->content->HrefValue = "";
			$item->content->TooltipValue = "";

			// price_wm
			$item->price_wm->LinkCustomAttributes = "";
			$item->price_wm->HrefValue = "";
			$item->price_wm->TooltipValue = "";

			// price_em
			$item->price_em->LinkCustomAttributes = "";
			$item->price_em->HrefValue = "";
			$item->price_em->TooltipValue = "";

			// price_wm_ahli
			$item->price_wm_ahli->LinkCustomAttributes = "";
			$item->price_wm_ahli->HrefValue = "";
			$item->price_wm_ahli->TooltipValue = "";

			// price_em_ahli
			$item->price_em_ahli->LinkCustomAttributes = "";
			$item->price_em_ahli->HrefValue = "";
			$item->price_em_ahli->TooltipValue = "";

			// weight
			$item->weight->LinkCustomAttributes = "";
			$item->weight->HrefValue = "";
			$item->weight->TooltipValue = "";

			// kod
			$item->kod->LinkCustomAttributes = "";
			$item->kod->HrefValue = "";
			$item->kod->TooltipValue = "";

			// rate
			$item->rate->LinkCustomAttributes = "";
			$item->rate->HrefValue = "";
			$item->rate->TooltipValue = "";

			// image
			$item->image->LinkCustomAttributes = "";
			$item->image->HrefValue = "";
			$item->image->TooltipValue = "";

			// bigimage
			$item->bigimage->LinkCustomAttributes = "";
			$item->bigimage->HrefValue = "";
			$item->bigimage->TooltipValue = "";

			// modified_date
			$item->modified_date->LinkCustomAttributes = "";
			$item->modified_date->HrefValue = "";
			$item->modified_date->TooltipValue = "";
		} elseif ($item->RowType == EW_ROWTYPE_EDIT) { // Edit row

			// id
			$item->id->EditCustomAttributes = "";
			$item->id->EditValue = $item->id->CurrentValue;
			$item->id->ViewCustomAttributes = "";

			// category_id
			$item->category_id->EditCustomAttributes = "";
			if ($item->category_id->getSessionValue() <> "") {
				$item->category_id->CurrentValue = $item->category_id->getSessionValue();
			if ($item->category_id->VirtualValue <> "") {
				$item->category_id->ViewValue = $item->category_id->VirtualValue;
			} else {
			if (strval($item->category_id->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($item->category_id->CurrentValue) . "";
			$sSqlWrk = "SELECT `name` FROM `category`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$item->category_id->ViewValue = $rswrk->fields('name');
					$rswrk->Close();
				} else {
					$item->category_id->ViewValue = $item->category_id->CurrentValue;
				}
			} else {
				$item->category_id->ViewValue = NULL;
			}
			}
			$item->category_id->ViewCustomAttributes = "";
			} else {
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `name` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld` FROM `category`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$item->category_id->EditValue = $arwrk;
			}

			// name
			$item->name->EditCustomAttributes = "";
			$item->name->EditValue = ew_HtmlEncode($item->name->CurrentValue);

			// description
			$item->description->EditCustomAttributes = "";
			$item->description->EditValue = ew_HtmlEncode($item->description->CurrentValue);

			// content
			$item->content->EditCustomAttributes = "";
			$item->content->EditValue = ew_HtmlEncode($item->content->CurrentValue);

			// price_wm
			$item->price_wm->EditCustomAttributes = "";
			$item->price_wm->EditValue = ew_HtmlEncode($item->price_wm->CurrentValue);

			// price_em
			$item->price_em->EditCustomAttributes = "";
			$item->price_em->EditValue = ew_HtmlEncode($item->price_em->CurrentValue);

			// price_wm_ahli
			$item->price_wm_ahli->EditCustomAttributes = "";
			$item->price_wm_ahli->EditValue = ew_HtmlEncode($item->price_wm_ahli->CurrentValue);

			// price_em_ahli
			$item->price_em_ahli->EditCustomAttributes = "";
			$item->price_em_ahli->EditValue = ew_HtmlEncode($item->price_em_ahli->CurrentValue);

			// weight
			$item->weight->EditCustomAttributes = "";
			$item->weight->EditValue = ew_HtmlEncode($item->weight->CurrentValue);

			// kod
			$item->kod->EditCustomAttributes = "";
			$item->kod->EditValue = ew_HtmlEncode($item->kod->CurrentValue);

			// rate
			$item->rate->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("5", $item->rate->FldTagCaption(1) <> "" ? $item->rate->FldTagCaption(1) : "5");
			$arwrk[] = array("4", $item->rate->FldTagCaption(2) <> "" ? $item->rate->FldTagCaption(2) : "4");
			$arwrk[] = array("3", $item->rate->FldTagCaption(3) <> "" ? $item->rate->FldTagCaption(3) : "3");
			$arwrk[] = array("2", $item->rate->FldTagCaption(4) <> "" ? $item->rate->FldTagCaption(4) : "2");
			$arwrk[] = array("1", $item->rate->FldTagCaption(5) <> "" ? $item->rate->FldTagCaption(5) : "1");
			$item->rate->EditValue = $arwrk;

			// image
			$item->image->EditCustomAttributes = "";
			if (!ew_Empty($item->image->Upload->DbValue)) {
				$item->image->EditValue = $item->image->Upload->DbValue;
				$item->image->ImageAlt = $item->image->FldAlt();
			} else {
				$item->image->EditValue = "";
			}

			// bigimage
			$item->bigimage->EditCustomAttributes = "";
			if (!ew_Empty($item->bigimage->Upload->DbValue)) {
				$item->bigimage->EditValue = $item->bigimage->Upload->DbValue;
				$item->bigimage->ImageAlt = $item->bigimage->FldAlt();
			} else {
				$item->bigimage->EditValue = "";
			}

			// modified_date
			// Edit refer script
			// id

			$item->id->HrefValue = "";

			// category_id
			$item->category_id->HrefValue = "";

			// name
			$item->name->HrefValue = "";

			// description
			$item->description->HrefValue = "";

			// content
			$item->content->HrefValue = "";

			// price_wm
			$item->price_wm->HrefValue = "";

			// price_em
			$item->price_em->HrefValue = "";

			// price_wm_ahli
			$item->price_wm_ahli->HrefValue = "";

			// price_em_ahli
			$item->price_em_ahli->HrefValue = "";

			// weight
			$item->weight->HrefValue = "";

			// kod
			$item->kod->HrefValue = "";

			// rate
			$item->rate->HrefValue = "";

			// image
			$item->image->HrefValue = "";

			// bigimage
			$item->bigimage->HrefValue = "";

			// modified_date
			$item->modified_date->HrefValue = "";
		}
		if ($item->RowType == EW_ROWTYPE_ADD ||
			$item->RowType == EW_ROWTYPE_EDIT ||
			$item->RowType == EW_ROWTYPE_SEARCH) { // Add / Edit / Search row
			$item->SetupFieldTitles();
		}

		// Call Row Rendered event
		if ($item->RowType <> EW_ROWTYPE_AGGREGATEINIT)
			$item->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
		global $Language, $gsFormError, $item;

		// Initialize form error message
		$gsFormError = "";
		if (!ew_CheckFileType($item->image->Upload->FileName)) {
			ew_AddMessage($gsFormError, $Language->Phrase("WrongFileType"));
		}
		if ($item->image->Upload->FileSize > 0 && EW_MAX_FILE_SIZE > 0 && $item->image->Upload->FileSize > EW_MAX_FILE_SIZE) {
			ew_AddMessage($gsFormError, str_replace("%s", EW_MAX_FILE_SIZE, $Language->Phrase("MaxFileSize")));
		}
		if (in_array($item->image->Upload->Error, array(1, 2, 3, 6, 7, 8))) {
			ew_AddMessage($gsFormError, $Language->Phrase("PhpUploadErr" . $item->image->Upload->Error));
		}
		if (!ew_CheckFileType($item->bigimage->Upload->FileName)) {
			ew_AddMessage($gsFormError, $Language->Phrase("WrongFileType"));
		}
		if ($item->bigimage->Upload->FileSize > 0 && EW_MAX_FILE_SIZE > 0 && $item->bigimage->Upload->FileSize > EW_MAX_FILE_SIZE) {
			ew_AddMessage($gsFormError, str_replace("%s", EW_MAX_FILE_SIZE, $Language->Phrase("MaxFileSize")));
		}
		if (in_array($item->bigimage->Upload->Error, array(1, 2, 3, 6, 7, 8))) {
			ew_AddMessage($gsFormError, $Language->Phrase("PhpUploadErr" . $item->bigimage->Upload->Error));
		}

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if (!is_null($item->category_id->FormValue) && $item->category_id->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $item->category_id->FldCaption());
		}
		if (!is_null($item->name->FormValue) && $item->name->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $item->name->FldCaption());
		}
		if (!is_null($item->content->FormValue) && $item->content->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $item->content->FldCaption());
		}
		if (!is_null($item->price_wm->FormValue) && $item->price_wm->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $item->price_wm->FldCaption());
		}
		if (!ew_CheckNumber($item->price_wm->FormValue)) {
			ew_AddMessage($gsFormError, $item->price_wm->FldErrMsg());
		}
		if (!is_null($item->price_em->FormValue) && $item->price_em->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $item->price_em->FldCaption());
		}
		if (!ew_CheckNumber($item->price_em->FormValue)) {
			ew_AddMessage($gsFormError, $item->price_em->FldErrMsg());
		}
		if (!is_null($item->price_wm_ahli->FormValue) && $item->price_wm_ahli->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $item->price_wm_ahli->FldCaption());
		}
		if (!ew_CheckNumber($item->price_wm_ahli->FormValue)) {
			ew_AddMessage($gsFormError, $item->price_wm_ahli->FldErrMsg());
		}
		if (!is_null($item->price_em_ahli->FormValue) && $item->price_em_ahli->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $item->price_em_ahli->FldCaption());
		}
		if (!ew_CheckNumber($item->price_em_ahli->FormValue)) {
			ew_AddMessage($gsFormError, $item->price_em_ahli->FldErrMsg());
		}
		if (!is_null($item->weight->FormValue) && $item->weight->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $item->weight->FldCaption());
		}
		if (!ew_CheckNumber($item->weight->FormValue)) {
			ew_AddMessage($gsFormError, $item->weight->FldErrMsg());
		}
		if (!is_null($item->kod->FormValue) && $item->kod->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $item->kod->FldCaption());
		}
		if ($item->rate->FormValue == "") {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $item->rate->FldCaption());
		}
		if ($item->image->Upload->Action == "3" && is_null($item->image->Upload->Value)) {
			ew_AddMessage($gsFormError, $Language->Phrase("EnterRequiredField") . " - " . $item->image->FldCaption());
		}

		// Return validate result
		$ValidateForm = ($gsFormError == "");

		// Call Form_CustomValidate event
		$sFormCustomError = "";
		$ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
		if ($sFormCustomError <> "") {
			ew_AddMessage($gsFormError, $sFormCustomError);
		}
		return $ValidateForm;
	}

	// Update record based on key values
	function EditRow() {
		global $conn, $Security, $Language, $item;
		$sFilter = $item->KeyFilter();
		$item->CurrentFilter = $sFilter;
		$sSql = $item->SQL();
		$conn->raiseErrorFn = 'ew_ErrorFn';
		$rs = $conn->Execute($sSql);
		$conn->raiseErrorFn = '';
		if ($rs === FALSE)
			return FALSE;
		if ($rs->EOF) {
			$EditRow = FALSE; // Update Failed
		} else {

			// Save old values
			$rsold =& $rs->fields;
			$rsnew = array();

			// category_id
			$item->category_id->SetDbValueDef($rsnew, $item->category_id->CurrentValue, 0, $item->category_id->ReadOnly);

			// name
			$item->name->SetDbValueDef($rsnew, $item->name->CurrentValue, NULL, $item->name->ReadOnly);

			// description
			$item->description->SetDbValueDef($rsnew, $item->description->CurrentValue, NULL, $item->description->ReadOnly);

			// content
			$item->content->SetDbValueDef($rsnew, $item->content->CurrentValue, NULL, $item->content->ReadOnly);

			// price_wm
			$item->price_wm->SetDbValueDef($rsnew, $item->price_wm->CurrentValue, NULL, $item->price_wm->ReadOnly);

			// price_em
			$item->price_em->SetDbValueDef($rsnew, $item->price_em->CurrentValue, NULL, $item->price_em->ReadOnly);

			// price_wm_ahli
			$item->price_wm_ahli->SetDbValueDef($rsnew, $item->price_wm_ahli->CurrentValue, NULL, $item->price_wm_ahli->ReadOnly);

			// price_em_ahli
			$item->price_em_ahli->SetDbValueDef($rsnew, $item->price_em_ahli->CurrentValue, NULL, $item->price_em_ahli->ReadOnly);

			// weight
			$item->weight->SetDbValueDef($rsnew, $item->weight->CurrentValue, NULL, $item->weight->ReadOnly);

			// kod
			$item->kod->SetDbValueDef($rsnew, $item->kod->CurrentValue, NULL, $item->kod->ReadOnly);

			// rate
			$item->rate->SetDbValueDef($rsnew, $item->rate->CurrentValue, NULL, $item->rate->ReadOnly);

			// image
			if ($item->image->Upload->Action == "1") { // Keep
			} elseif ($item->image->Upload->Action == "2" || $item->image->Upload->Action == "3") { // Update/Remove
			$item->image->Upload->DbValue = $rs->fields('image'); // Get original value
			if (is_null($item->image->Upload->Value)) {
				$rsnew['image'] = NULL;
			} else {
				if ($item->image->Upload->FileName == $item->image->Upload->DbValue) { // Upload file name same as old file name
					$rsnew['image'] = $item->image->Upload->FileName;
				} else {
					$rsnew['image'] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $item->image->UploadPath), $item->image->Upload->FileName);
				}
			}
			}

			// bigimage
			if ($item->bigimage->Upload->Action == "1") { // Keep
			} elseif ($item->bigimage->Upload->Action == "2" || $item->bigimage->Upload->Action == "3") { // Update/Remove
			$item->bigimage->Upload->DbValue = $rs->fields('bigimage'); // Get original value
			if (is_null($item->bigimage->Upload->Value)) {
				$rsnew['bigimage'] = NULL;
			} else {
				if ($item->bigimage->Upload->FileName == $item->bigimage->Upload->DbValue) { // Upload file name same as old file name
					$rsnew['bigimage'] = $item->bigimage->Upload->FileName;
				} else {
					$rsnew['bigimage'] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $item->bigimage->UploadPath), $item->bigimage->Upload->FileName);
				}
			}
			}

			// modified_date
			$item->modified_date->SetDbValueDef($rsnew, ew_CurrentDateTime(), NULL);
			$rsnew['modified_date'] =& $item->modified_date->DbValue;

			// Call Row Updating event
			$bUpdateRow = $item->Row_Updating($rsold, $rsnew);
			if ($bUpdateRow) {
			if (!ew_Empty($item->image->Upload->Value)) {
				if ($item->image->Upload->FileName == $item->image->Upload->DbValue) { // Overwrite if same file name
					$item->image->Upload->SaveToFile($item->image->UploadPath, $rsnew['image'], TRUE);
					$item->image->Upload->DbValue = ""; // No need to delete any more
				} else {
					$item->image->Upload->SaveToFile($item->image->UploadPath, $rsnew['image'], FALSE);
				}
			}
			if ($item->image->Upload->Action == "2" || $item->image->Upload->Action == "3") { // Update/Remove
				if ($item->image->Upload->DbValue <> "")
					@unlink(ew_UploadPathEx(TRUE, $item->image->UploadPath) . $item->image->Upload->DbValue);
			}
			if (!ew_Empty($item->bigimage->Upload->Value)) {
				if ($item->bigimage->Upload->FileName == $item->bigimage->Upload->DbValue) { // Overwrite if same file name
					$item->bigimage->Upload->SaveToFile($item->bigimage->UploadPath, $rsnew['bigimage'], TRUE);
					$item->bigimage->Upload->DbValue = ""; // No need to delete any more
				} else {
					$item->bigimage->Upload->SaveToFile($item->bigimage->UploadPath, $rsnew['bigimage'], FALSE);
				}
			}
			if ($item->bigimage->Upload->Action == "2" || $item->bigimage->Upload->Action == "3") { // Update/Remove
				if ($item->bigimage->Upload->DbValue <> "")
					@unlink(ew_UploadPathEx(TRUE, $item->bigimage->UploadPath) . $item->bigimage->Upload->DbValue);
			}
				$conn->raiseErrorFn = 'ew_ErrorFn';
				if (count($rsnew) > 0)
					$EditRow = $conn->Execute($item->UpdateSQL($rsnew));
				else
					$EditRow = TRUE; // No field to update
				$conn->raiseErrorFn = '';
			} else {
				if ($item->CancelMessage <> "") {
					$this->setFailureMessage($item->CancelMessage);
					$item->CancelMessage = "";
				} else {
					$this->setFailureMessage($Language->Phrase("UpdateCancelled"));
				}
				$EditRow = FALSE;
			}
		}

		// Call Row_Updated event
		if ($EditRow)
			$item->Row_Updated($rsold, $rsnew);
		$rs->Close();

		// image
		$item->image->Upload->RemoveFromSession(); // Remove file value from Session

		// bigimage
		$item->bigimage->Upload->RemoveFromSession(); // Remove file value from Session
		return $EditRow;
	}

	// Set up master/detail based on QueryString
	function SetUpMasterParms() {
		global $item;
		$bValidMaster = FALSE;

		// Get the keys for master table
		if (@$_GET[EW_TABLE_SHOW_MASTER] <> "") {
			$sMasterTblVar = $_GET[EW_TABLE_SHOW_MASTER];
			if ($sMasterTblVar == "") {
				$bValidMaster = TRUE;
				$this->DbMasterFilter = "";
				$this->DbDetailFilter = "";
			}
			if ($sMasterTblVar == "category") {
				$bValidMaster = TRUE;
				if (@$_GET["id"] <> "") {
					$GLOBALS["category"]->id->setQueryStringValue($_GET["id"]);
					$item->category_id->setQueryStringValue($GLOBALS["category"]->id->QueryStringValue);
					$item->category_id->setSessionValue($item->category_id->QueryStringValue);
					if (!is_numeric($GLOBALS["category"]->id->QueryStringValue)) $bValidMaster = FALSE;
				} else {
					$bValidMaster = FALSE;
				}
			}
		}
		if ($bValidMaster) {

			// Save current master table
			$item->setCurrentMasterTable($sMasterTblVar);

			// Reset start record counter (new master key)
			$this->StartRec = 1;
			$item->setStartRecordNumber($this->StartRec);

			// Clear previous master key from Session
			if ($sMasterTblVar <> "category") {
				if ($item->category_id->QueryStringValue == "") $item->category_id->setSessionValue("");
			}
		}
		$this->DbMasterFilter = $item->getMasterFilter(); //  Get master filter
		$this->DbDetailFilter = $item->getDetailFilter(); // Get detail filter
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	// $type = ''|'success'|'failure'
	function Message_Showing(&$msg, $type) {

		// Example:
		//if ($type == 'success') $msg = "your success message";

	}

	// Page Data Rendering event
	function Page_DataRendering(&$header) {

		// Example:
		//$header = "your header";

	}

	// Page Data Rendered event
	function Page_DataRendered(&$footer) {

		// Example:
		//$footer = "your footer";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

		// Return error message in CustomError
		return TRUE;
	}
}
?>
